package com.aigou.admin.service.impl;

import com.aigou.admin.dao.OrderProductDAO;
import com.aigou.admin.dao.impl.OrderProductDAOImpl;
import com.aigou.admin.entity.OrderProduct;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.service.OrderProductService;

import java.util.List;

public class OrderProductServiceImpl implements OrderProductService {

    private OrderProductDAO orderProductDAO = new OrderProductDAOImpl();

    @Override
    public List<OrderProduct> getAllOrderProducts() {
        return orderProductDAO.getAllOrderProducts();
    }

    @Override
    public OrderProduct getOrderProductById(String id) {
        return orderProductDAO.getOrderProductById(id);
    }

    @Override
    public int addOrderProduct(OrderProduct orderProduct) {
        return orderProductDAO.addOrderProduct(orderProduct);
    }

    @Override
    public int deleteOrderProduct(String id) {
        return orderProductDAO.deleteOrderProduct(id);
    }

    @Override
    public int updateOrderProduct(OrderProduct orderProduct) {
        return orderProductDAO.updateOrderProduct(orderProduct);
    }

    @Override
    public PageEntity<OrderProduct> findOrderProductPage(Integer current, Integer pageSize) {

        // 查询总记录数
        int total = orderProductDAO.selectOrderProductCount();
        // 查询当前页数据
        List<OrderProduct> orderProducts = orderProductDAO.selectOrderProductLimits((current - 1) * pageSize, pageSize);
        // 包装数据发送给前端
        PageEntity<OrderProduct> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(orderProducts);
        return pageEntity;
    }
}
